<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\AdapterWebController;
use App\Modules\Company\Company;
use Illuminate\Http\Request;


class CompanyController extends AdapterWebController
{

    /**
     * 添加公司
     */
    public function addCompany(Request $request)
    {
        if ($request->isMethod('get')) {
            return view('admin.company.add_company');
        }
        $postData = $request->all();
        $this->appLayerExec(Company::class, 'addCompany', $postData);
        flash('添加成功')->success();
        return redirect()->back();
    }

    //公司列表
    public function companyList(){
        $res = $this->appLayerExec(Company::class, 'companyList');
        return view("admin.company.company_list", ['list' => $res['res'],'company'=>1,'companyStatus'=>1,'companyList'=>1]);
    }

    //修改公司
    public function updateCompany(Request $request){
        if ($request->isMethod('get')) {
            $postData['id'] = $request['id'];
            $detail = $this->appLayerExec(Company::class, 'companyDetail', $postData);
            $detail = $detail['res'];
            return view('admin.company.amend_message', compact('detail'));
        }
        $postData = $request->all();
        if (empty($postData['company_image'])) {
            unset($postData['company_image']);
        }
        $this->appLayerExec(Company::class, 'updateCompany', $postData);
        return redirect()->back();
    }
}